﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Calcite.Classes
{
    public partial class PreviewGridView : DataGridView
    {

        
        internal DataGridViewCellStyle headerRowStyle; 
        internal DataGridViewCellStyle unitsRowStyle;
        internal DataGridViewCellStyle skippedRowStyle;
            
        public PreviewGridView()
        {
            InitializeComponent();
            // Set the styles for rows
            this.headerRowStyle = new DataGridViewCellStyle(this.DefaultCellStyle);
            this.unitsRowStyle = new DataGridViewCellStyle(this.DefaultCellStyle);
            this.skippedRowStyle = new DataGridViewCellStyle(this.DefaultCellStyle);
            // Bold and blue for header
            this.headerRowStyle.Font = new Font(this.DefaultCellStyle.Font.FontFamily, 
                    this.Font.Size, FontStyle.Bold);
            headerRowStyle.BackColor = Color.LightPink;
            // Italic and pink for units
            unitsRowStyle.Font = new Font(this.DefaultCellStyle.Font.FontFamily,
                this.Font.Size, FontStyle.Italic);
            unitsRowStyle.BackColor = Color.PowderBlue;
            // Greyed out text for skipped lines
            skippedRowStyle.ForeColor = Color.Gray;
        }

        public void ExpandColumns(int numCols) 
        {
            while (this.Columns.Count < numCols)
            {
                DataGridViewTextBoxColumn dgvc = new DataGridViewTextBoxColumn();
                this.Columns.Add(dgvc);
              
            }
        }

        //public PreviewGridView(IContainer container)
        //{
        //    container.Add(this);
        //    InitializeComponent();
        //}

        protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
        // Use OnRowPostPaint event to draw row numbers on row headers
        // Taken from http://www.danielsoper.com/programming/DataGridViewNumberedRows.aspx
        {
            string strRowNumber = (e.RowIndex + 1).ToString();
            //prepend leading zeros to the string
            while (strRowNumber.Length < this.RowCount.ToString().Length) strRowNumber = "0" + strRowNumber;
            //determine the display size of the row number string using
            //the DataGridView's current font.
            SizeF size = e.Graphics.MeasureString(strRowNumber, this.Font);
            //adjust the width of the column that contains the row header cells 
            //if necessary
            if (this.RowHeadersWidth < (int)(size.Width + 20)) this.RowHeadersWidth = (int)(size.Width + 20);
            //this brush will be used to draw the row number string on the
            //row header cell using the system's current ControlText color
            Brush b = SystemBrushes.ControlText;
            //draw the row number string on the current row header cell using
            //the brush defined above and the DataGridView's default font
            e.Graphics.DrawString(strRowNumber, this.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2));
            //call the base object's OnRowPostPaint method
            base.OnRowPostPaint(e);
        }



    }
}
